跳到主要内容

APT 使用

annotation-processor模块

JAVA APT 基于注解处理器,本工程案例只是输出一些打印内容。

写一个processor

example file

如果想了解更多注解处理器相关的知识,请阅读 Core-Java-Vol.-II-Advanced-Features-12th-Edition-Cay-S.-Horstmann.

如果在其它工程使用Processor jar包


<!--...-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>com.whalefall</groupId>
<artifactId>annotation-processor</artifactId>
<version>0.0.1-SNAPSHOT</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
</path>
</annotationProcessorPaths>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!--...Here are include lombok, thus I use the plugin.-->